<?php

namespace app\adminapi\export;

use app\services\product\product\StoreProductTemplateServices;
use Carbon\Carbon;

class StoreProductTemplateExport extends BaseExport
{
    protected $header = [
        '模版ID', '最新编辑日期', '模版名称', '商品参数'
    ];

    public function createData(array $where)
    {
        $list = app()->make(StoreProductTemplateServices::class)->getList($where)['list'];
        $data = [];
        foreach ($list as $item) {
            foreach ($item->merchant_params as $k1 => $item2) {
                $data[] = [
                    ($k1 == 0) ? $item['id'] ?? '' :'',
                    ($k1 == 0 && $item['upd_time']) ? Carbon::parse($item['upd_time'])->format('Y-m-d H:i:s') :'',
                    ($k1 == 0) ? $item['template_name'] ?? '' :'',
                    $item2 ?? ''
                ];
            }
        }
        return $data;
    }
}